package IOC.C2_resources.C2_3_resourcesImplementations.C2_3_7_resourcesImplementationsBytearrayresource;

import org.junit.Test;
import org.springframework.core.io.ByteArrayResource;
import org.springframework.core.io.Resource;

import java.io.InputStream;

/**
 * @author xufy
 * @version 1.0
 **/
public class ByteArrayResourceTest {

    //loading content from any given byte array
    @Test
    public void loadAndReadUrlResource() throws Exception {

        Resource resource = new ByteArrayResource("Hello World!".getBytes());

        InputStream is = null;
        try {
            is = resource.getInputStream();
            byte[] descBytes = new byte[is.available()];
            is.read(descBytes);
            System.out.println("??：   " +new String(descBytes));
        } catch (Exception e) {
            e.printStackTrace();
        } finally {
            try {
                is.close();
            } catch (Exception e) {
            }
        }

    }
}
